/**
 * 
 */
package org.jft.datamodel.database.mapping;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.jft.datamodel.config.Constants;
import org.jft.datamodel.database.dao.DAOFactory;

/**
 * @author LAP
 *
 */
@Entity
@Table(name = "event_id")
public class Event {
	
	@Id
	@GeneratedValue(generator = "Increment")
	@GenericGenerator(name = "Increment", strategy = "Increment")
	@Column(name = "event_id", nullable = false)
	private Long eventId;
	
	@Column(name = "event_class_id", nullable = false)
	private Long eventClassId;
	
	@Column(name = "event_date", nullable = false)
	private Long eventDate;
	
	@ManyToOne
	@JoinColumn(name = "event_class_id")
	private EventClass eventClass;
	
	@ManyToMany(mappedBy = "events")
	private List<Person> persons;
	
	@ManyToMany(mappedBy = "events")
	private List<Couple> couples;
	
	public Event() throws SQLException {
		eventDate = new Date().getTime();
		setEventClass(DAOFactory.getinstance().getEventClassDAO().getByID(Constants.BIRTH_EVENT_CLASS_ID));
	}
	
	public Long getId() {
		return eventId;
	}
	
	public void setId(Long value) {
		eventId = value;
	}
	
	public Long getEventDate() {
		return eventDate;
	}
	
	public void setEventDate(Long value) {
		eventDate = value;
	}
	
	public Long getEventClassId() {
		return eventClassId;
	}
	
	public void setEventClassId(Long value) {
		eventClassId = value;
	}
	
	public EventClass getEventClass() {
		return eventClass;
	}
	
	public void setEventClass(EventClass value) {
		eventClass = value;
		setEventClassId(value.getId());
	}

	public List<Person> getPersons() {
		return persons;
	}

	public List<Couple> getCouples() {
		return couples;
	}
}
